package com.baizhi.service.ServiceImpl;

import com.baizhi.annotation.LogAnnotation;
import com.baizhi.dao.GuruDao;
import com.baizhi.entity.Guru;
import com.baizhi.service.GuruService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2019/4/7.
 */
@Service
public class GuruServiceImpl implements GuruService {
    @Autowired
    private GuruDao guruDao;

    @Override
    @LogAnnotation("查询所有上师")
    public Map selectAllGuru(int rows, int page, String gurnName) {
        Map map=new HashMap();
        if(gurnName!=null){
            if("".equals(gurnName)){
                gurnName=null;
            }else{
                gurnName="%"+gurnName+"%";
            }
        }
        int begin=rows*(page-1);
        int size=rows;
        Integer count=guruDao.selectAllGuruCount(gurnName);
        List<Guru> gurns=guruDao.selectAllGuru(begin,size,gurnName);

        map.put("total",count);
        map.put("rows",gurns);
        return map;
    }

    @Override
    public Map addGuru(Guru gurn) {
        Map map=new HashMap();
        try {
            guruDao.addGuru(gurn);
            map.put("isok",true);
        } catch (Exception e) {
            map.put("isok",false);
        }
        return  map;
    }

    @Override
    public Map delateGuru(Integer[] ids) {
        Map map=new HashMap();
        try {
            guruDao.delateGuru(ids);
            map.put("isok",true);
        } catch (Exception e) {
            map.put("isok",false);
        }
        return  map;
    }

    @Override
    public Map updateGuru(Guru gurn) {
        Map map=new HashMap();
        try {
            guruDao.updateGuru(gurn);
            map.put("isok",true);
        } catch (Exception e) {
            map.put("isok",false);
        }
        return  map;
    }

    @Override
    public Map selectAllGuru2() {
        Map map=new HashMap();
        List<Guru> gurns=guruDao.selectAllGuru2();
        map.put("rows",gurns);
        return map;
    }
}
